package com.youhong.teethcare;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.widget.TextView;

import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import com.prolificinteractive.materialcalendarview.OnDateSelectedListener;
import com.youhong.teethcare.decorators.BiggerTextDecorator;
import com.youhong.teethcare.decorators.HasDataDecorator;
import com.youhong.teethcare.decorators.MySelectorDecorator;
import com.youhong.teethcare.services.Common;
import com.youhong.teethcare.services.MyApplication;
import com.youhong.teethcare.utils.LanguageUtils;

import java.util.Calendar;

public class DatePickerActivity extends Activity implements OnDateSelectedListener {

    TextView tv_month;

    MaterialCalendarView mcv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_date_picker);

        Calendar c = (Calendar) getIntent().getSerializableExtra("date");
        mcv = findViewById(R.id.datePicker_mcv);
        mcv.setCurrentDate(c.getTime());
        mcv.setSelectedDate(c.getTime());
        mcv.setOnDateChangedListener(this);
        mcv.removeDecorators();
        mcv.addDecorators(
                new HasDataDecorator(getApplicationContext())
        );

    }

    @Override
    protected void onStart() {


        super.onStart();
    }

    public static String returnMonth(Context mContext, int month) {

        return mContext.getResources().getStringArray(R.array.months)[month];

    }

    Handler handler = new Handler();

    @Override
    public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
        Calendar c = Calendar.getInstance();

        c.setTime(date.getDate());

        handler.post(new Runnable() {
            @Override
            public void run() {
                Intent return_intent = new Intent();
                return_intent.putExtra("date", c);
                DatePickerActivity.this.setResult(Activity.RESULT_OK, return_intent);
                DatePickerActivity.this.finish();

            }
        });


    }
}

